﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace EntityDA
{
    public class ThanhVienDB
    {
        //Lấy tất cả thành viên
        public List<ThanhVienData> GetAllThanhVien()
        {
            List<ThanhVienData> DSThanhVien = new List<ThanhVienData>();
            ConnectionDB cn = new ConnectionDB();
            string sql = "select * from ThanhVien";
            cn.cmd.CommandText = sql;
            SqlDataReader reader = cn.cmd.ExecuteReader();
            ThanhVienData ThanhVien = null;
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    ThanhVien = new ThanhVienData();
                    if (!reader.IsDBNull(0))
                        ThanhVien.MaTV = reader.GetInt32(0);
                    if (!reader.IsDBNull(1))
                        ThanhVien.TenDN = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                        ThanhVien.MatKhau = reader.GetString(2);
                    if (!reader.IsDBNull(3))
                        ThanhVien.TenTV = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                        ThanhVien.DiaChi = reader.GetString(4);
                    if (!reader.IsDBNull(5))
                        ThanhVien.DienThoai = reader.GetString(5);
                    if (!reader.IsDBNull(6))
                        ThanhVien.Email = reader.GetString(6);
                    if (!reader.IsDBNull(7))
                        ThanhVien.Quyen = reader.GetInt32(7);

                    DSThanhVien.Add(ThanhVien);
                }
            }
            return DSThanhVien;
        }
    }
}